package cn.miao.config;

import io.swagger.models.Swagger;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;

import java.util.ArrayList;
import java.util.List;

/**
 * 使用zuul网关整合所有微服务的swagger
 *
 * @author MiaoDaWei
 * @date 2021/11/21
 */
@Component
@Primary
public class DocumentationConfig implements SwaggerResourcesProvider {
    @Override
    public List<SwaggerResource> get() {
       List<SwaggerResource> resources = new ArrayList<>();
       resources.add(swaggerResource("系统管理", "/hrm/system/v2/api-docs", "2.0"));
       resources.add(swaggerResource("认证管理", "/hrm/auth/v2/api-docs", "2.0"));
       resources.add(swaggerResource("文件管理", "/hrm/file/v2/api-docs", "2.0"));
       resources.add(swaggerResource("课程管理", "/hrm/course/v2/api-docs", "2.0"));
       resources.add(swaggerResource("ES管理", "/hrm/search/v2/api-docs", "2.0"));
       resources.add(swaggerResource("用户管理", "/hrm/user/v2/api-docs", "2.0"));
       //...如果多个就配置多个
       return resources;
    }

    /**
     * swagger资源配置
     *
     * @param name     的名字
     * @param location 位置
     * @param version  版本
     * @return {@link SwaggerResource}
     */
    private SwaggerResource swaggerResource(String name, String location, String version) {
        SwaggerResource swaggerResource = new SwaggerResource();
        swaggerResource.setName(name);
        swaggerResource.setLocation(location);
        swaggerResource.setSwaggerVersion(version);
        return swaggerResource;
    }
}